home *** CD-ROM | disk | FTP | other *** search
/ SGI Developer Toolbox 6.1 / SGI Developer Toolbox 6.1 - Disc 4.iso / public / rsynth / src / klatt.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-08-02  |  4.4 KB  |  226 lines

  1. /*
  2. title:  KLATT.C
  3.  
  4. author: Jon Iles (j.p.iles@uk.ac.bham.cs)
  5.  
  6. notes:  This file contains C code to provide a simple interface to
  7.         Dennis Klatt's parwave function. This function, as the name
  8.         suggests, converts a frame of parameters into a waveform.
  9.         The parwave function itself is a translation of the Dennis's
  10.  original Fortran code, as published in JASA. The code was
  11.  posted to comp.speech in 1993, and has been updated by me
  12.  to fix a number of bugs.
  13.  
  14.  See the README_klatt file for more details.
  15. */
  16.  
  17.  
  18. #include <stdio.h>
  19. #include <string.h>
  20. #include <stdlib.h>
  21. #include "proto.h"
  22. #include "parwave.h"
  23.  
  24. #define MAX_SAM           20000
  25.  
  26. int synthesis_model = ALL_PARALLEL;
  27.                                     /* CASCADE_PARALLEL needs nfcascade, say 5 */
  28. long nfcascade = 0;
  29.                                 /* Number of formants in cascade vocal tract    */
  30. long samp_rate = 10000;
  31.                                 /* Number of output samples per second           */
  32. long nspfr;          /* Number of samples per frame */
  33.  
  34. void
  35. usage PROTO((void))
  36. {
  37.  printf("Options...\n");
  38.  printf("-h Displays this message\n");
  39.  printf("-i <infile> sets input filename\n");
  40.  printf("-o <outfile> sets output filename\n");
  41.  printf("   If output filename not specified, stdout is used\n");
  42.  printf("-q quiet - print no messages\n");
  43.  printf("-t <n> select output waveform\n");
  44.  printf("-c select cascade-parallel configuration\n");
  45.  printf("   Parallel configuration is default\n");
  46.  printf("-n <number> Number of formants in cascade branch.\n");
  47.  printf("   Default is 5\n");
  48.  printf("-s <n> set sample rate\n");
  49.  printf("-f <n> set number of milliseconds per frame\n");
  50.  printf("-v Specifies that the impulse voicing source is used\n");
  51.  printf("   Default is natural voicing\n");
  52.  printf("-F <percent> percentage of f0 flutter\n");
  53.  printf("    Default is 0\n");
  54. }
  55.  
  56. extern int optind;
  57. extern char *optarg;
  58. extern int getopt PROTO((int argc, char **argv, char *opt));
  59.  
  60. extern int main PROTO((int argc, char **argv));
  61.  
  62. int
  63. main(argc, argv)
  64.  
  65. int argc;
  66. char *argv[];
  67.  
  68. {
  69.  char c;
  70.  char infile[80];
  71.  char outfile[80];
  72.  FILE *infp;
  73.  FILE *outfp;
  74.  
  75.  int result;
  76.  int flag;
  77.  int value;
  78.  short iwave[MAX_SAM];
  79.  int isam;
  80.  int icount;
  81.  int par_count;
  82.  int nmspf_def;
  83.  
  84.  if (argc == 1)
  85.   {
  86.    usage();
  87.    exit(1);
  88.   }
  89.  
  90.  strcpy(infile, "");
  91.  strcpy(outfile, "");
  92.  quiet_flag = FALSE;
  93.  synthesis_model = ALL_PARALLEL;
  94.  samp_rate = 10000;
  95.  glsource = NATURAL;
  96.  nmspf_def = 10;
  97.  
  98.  nfcascade = 0;
  99.  outsl = 0;
  100.  f0_flutter = 0;
  101.  
  102.  while ((c = getopt(argc, argv, "i:o:t:s:f:n:F:vqch")) != EOF)
  103.   {
  104.    switch (c)
  105.     {
  106.      case 'i':
  107.       strcpy(infile, optarg);
  108.       break;
  109.      case 'o':
  110.       strcpy(outfile, optarg);
  111.       break;
  112.      case 'q':
  113.       quiet_flag = TRUE;
  114.       break;
  115.      case 't':
  116.       outsl = atoi(optarg);
  117.       break;
  118.      case 'c':
  119.       synthesis_model = CASCADE_PARALLEL;
  120.       nfcascade = 5;
  121.       break;
  122.      case 's':
  123.       samp_rate = atoi(optarg);
  124.       break;
  125.      case 'f':
  126.       nmspf_def = atoi(optarg);
  127.       break;
  128.      case 'v':
  129.       glsource = IMPULSIVE;
  130.       break;
  131.      case 'h':
  132.       usage();
  133.       exit(1);
  134.       break;
  135.      case 'n':
  136.       nfcascade = atoi(optarg);
  137.       break;
  138.      case 'F':
  139.       f0_flutter = atoi(optarg);
  140.       break;
  141.     }
  142.   }
  143.  
  144.  nspfr = (samp_rate * nmspf_def) / 1000;
  145.  
  146.  if (strcmp(infile, "") == 0)
  147.   {
  148.    printf("Enter name of input parameter file: ");
  149.    scanf("%s", infile);
  150.   }
  151.  
  152.  infp = fopen(infile, "r");
  153.  if (infp == NULL)
  154.   {
  155.    perror("can't open input file");
  156.    exit(1);
  157.   }
  158.  
  159.  if (strcmp(outfile, "") == 0)
  160.   {
  161.    outfp = stdout;
  162.    quiet_flag = TRUE;
  163.   }
  164.  else
  165.   {
  166.    outfp = fopen(outfile, "w");
  167.    if (outfp == NULL)
  168.     {
  169.      perror("can't open output file");
  170.      exit(1);
  171.     }
  172.   }
  173.  
  174.  initsw = 0;
  175.  warnsw = 0;
  176.  dispt = 0;
  177.  disptcum = 0;
  178.  icount = 0;
  179.  flag = FALSE;
  180.  
  181.  while (flag == FALSE)
  182.   {
  183.    union
  184.     {
  185.      klatt_t klatt;
  186.      long array[NPAR];
  187.     }
  188.    pars;
  189.  
  190.    for (par_count = 0; par_count < NPAR; ++par_count)
  191.     {
  192.      result = fscanf(infp, "%i", &value);
  193.      pars.array[par_count] = value;
  194.     }
  195.  
  196.    if (result == EOF)
  197.     {
  198.      flag = TRUE;
  199.     }
  200.    else
  201.     {
  202.      parwav(&pars.klatt, &iwave[0]);
  203.  
  204.      if (quiet_flag == FALSE)
  205.       {
  206.        printf("\rFrame %i", icount);
  207.        fflush(stdout);
  208.       }
  209.  
  210.      for (isam = 0; isam < nspfr; ++isam)
  211.       {
  212.        fprintf(outfp, "%i\n", iwave[isam]);
  213.       }
  214.      icount++;
  215.     }
  216.   }
  217.  fclose(infp);
  218.  fclose(outfp);
  219.  
  220.  if (quiet_flag == FALSE)
  221.   {
  222.    printf("\nDone\n");
  223.   }
  224.  return 0;
  225. }
  226.